package utils;

import org.apache.commons.lang.StringUtils;

import java.util.Objects;

/**
 * @program: util
 * @description: 一些工具类
 * @author: zhouliangliang
 * @create: 2020-03-05 19:48
 **/
public class CommonUtils {

    /**
     * 比对版本号大小
     * 版本号格式为 数字.数字形式
     * 2.3.0, 2.3.2等
     * 逻辑为按照数字分隔，比对数字
     * @param paramVersion
     * @param constantVersion
     * @return
     */
    private boolean compareVersion(String paramVersion, String constantVersion) {
        try {
            if(StringUtils.isEmpty(paramVersion) || StringUtils.isEmpty(constantVersion)) {
                return false;
            }

            if(Objects.equals(paramVersion, constantVersion)) {
                return true;
            }

            String []paramArray = paramVersion.split("\\.");
            String []conArray = constantVersion.split("\\.");
            int length = paramArray.length > conArray.length ? conArray.length : paramArray.length;
            for(int i=0; i < length; i++) {
                if(Integer.valueOf(paramArray[i]) > Integer.valueOf(conArray[i]) ) {
                    return true;
                } else if(Integer.valueOf(paramArray[i]) < Integer.valueOf(conArray[i])) {
                    return false;
                } else {
                    continue;
                }
            }

            if(paramVersion.length() > constantVersion.length()) {
                return true;
            }

            return false;
        } catch (Exception e) {
            return false;
        }

    }
}
